from .pool import Pool
from .dbconnection import DbConnection


class Db(DbConnection):

    def __init__(self, pool=None, **kwargs):
        DbConnection.__init__(self, self.getPool(pool, **kwargs), **kwargs)

    def getPool(self, pool, **kwargs):
        if isinstance(pool, str):
            pool = globals()[pool + '_pool']
        if pool is None:
            pool = Pool(**kwargs)
        #  print(pool)
        return pool


api_pool = None


def init_db():
    global api_pool
    api_pool = Pool(db='RRYAOZgf', host='mysql.tang.com', port=17386,
                    user='eao2X5GNAsF', passwd='kts5Y3Y/ij$kJU')

